﻿function GetHex(englishClass)
    if englishClass == "HUNTER" then hexcolor = "ABD473"
    elseif englishClass == "WARLOCK" then hexcolor = "ABD473"
    elseif englishClass == "PRIEST" then hexcolor = "FFFFFF"
    elseif englishClass == "PALADIN" then hexcolor = "F58CBA"
    elseif englishClass == "MAGE" then hexcolor = "69CCF0"
    elseif englishClass == "ROGUE" then hexcolor = "7f7f7f"
    elseif englishClass == "DRUID" then hexcolor = "FF7D0A"
    elseif englishClass == "SHAMAN" then hexcolor = "0070DE"
    elseif englishClass == "WARRIOR" then hexcolor = "C79C6E"
    elseif englishClass == "DEATHKNIGHT" then hexcolor = "C41F3B"
    end
    return hexcolor
end

function Maiks:CURSOR_UPDATE()
    local unit = "mouseover"
    if CheckInteractDistance(unit, 1) and UnitIsPlayer(unit) then
        Maiks:EnemyRange(unit)
    end
end

function Maiks:PLAYER_FOCUS_CHANGED()
    local unit = "focus"
        if UnitIsPlayer(unit) then
        Maiks:EnemyRange(unit)
    end
end

function Maiks:PLAYER_TARGET_CHANGED()
    local unit = "target"
        if UnitIsPlayer(unit) then
        Maiks:EnemyRange(unit)
    end
end

function Maiks:EnemyRange(unit)
    local enemymsg, enemyname, zone;
    if UnitIsEnemy("player",unit) then
    local enemyname = strtrim(GetUnitName(unit, false), " (*)")
        local zone = GetMinimapZoneText()
        local _,englishClass = UnitClass(unit)
        local hex = GetHex(englishClass)
        if enemymsg == enemyname.."|"..zone then else
            local enemymsg = enemyname.."|"..zone.."|"..hex;
            Maiks:SendCommMessage("Maiks_RBG_Enemy", enemymsg, "BATTLEGROUND")
        end
    end
end
